package com.qth.valet.common.netty;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HandlerHeartBeat extends ChannelDuplexHandler {
    @Override // 用来触发特殊事件
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
        IdleStateEvent event = (IdleStateEvent) evt;
        // 触发读空闲事件
        if (event.state() == IdleState.READER_IDLE) {
            log.info("5秒没收到客户端消息，关闭通道");
            ctx.close();
        }
    }
}

